package com.dhcc.DRGsHosp.application.impl;

import java.util.List;
import java.util.Map;

import javax.inject.Named;

import org.dayatang.domain.EntityRepository;
import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.QueryChannelService;
import org.springframework.transaction.annotation.Transactional;

import com.dhcc.DRGsHosp.application.CliSpecApplication;
import com.dhcc.DRGsHosp.core.domain.CliSpec;

/**
 * @title		: CliSpecApplicationImpl.java 
 * @description	: 
 * @author		: chl
 * @date		: 2016年12月7日
 * @version     : 2016
 * @copyright   : DHCC 
 */
@Named
@Transactional
public class CliSpecApplicationImpl implements CliSpecApplication {
	private QueryChannelService queryChannel;
	private EntityRepository repository ;
	
	private EntityRepository getEntityRepository() {
		if(repository == null ){
			repository = InstanceFactory.getInstance(EntityRepository.class, "repository" ) ;
		}
		return repository;
	}
	private QueryChannelService getQueryChannelService(){
	       if(queryChannel==null){
	          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
	       }
	     return queryChannel;
	}
	@Override
	public List<CliSpec> findAllCliSpecs() {
		// TODO Auto-generated method stub
		String jpql = "select cs from  CliSpec cs" ;
		return getEntityRepository().createJpqlQuery(jpql).list() ;
	}
	@Override
	public void save(CliSpec entity) {
		// TODO Auto-generated method stub
		entity.save();
	}
	@Override
	public void update(Map<String,Object> map) {
		// TODO Auto-generated method stub
		String sql = "update drgs.t_clispec cs set cs.spec_desc = :specDesc ,cs.spec_mark = :specMark where spec_code = :specCode " ;
		getEntityRepository().createSqlQuery(sql).setParameters(map).executeUpdate() ;
	}
	@Override
	public void deleteByCode(String specCode) {
		// TODO Auto-generated method stub
		String jpql = "delete from CliSpec cs where cs.specCode = :specCode" ; 
		getEntityRepository().createJpqlQuery(jpql).addParameter("specCode", specCode).executeUpdate() ;
	}
	@Override
	public List<Object> excuteQuery(String sql, Map<String, Object> condition) {
		// TODO Auto-generated method stub
		return getEntityRepository().createSqlQuery(sql).setParameters(condition).list();
	}
	@Override
	public int excuteUpdate(String sql, Map<String, Object> condition) {
		// TODO Auto-generated method stub
		return getEntityRepository().createSqlQuery(sql).setParameters(condition).executeUpdate();
	}
}
